<?php
//文件名 login-html.php
//连接数据库，获取用户名密码
$username=$_POST['username'];
$password=$_POST['password'];
$link=mysqli_connect('127.0.0.1','root','root','books-system');
mysqli_set_charset($link, 'utf8');

$query="select * from user  LEFT JOIN role ON user.roleid=role.roleid WHERE `user`.username='$username' ";
$result=mysqli_query($link, $query);

$data=mysqli_fetch_all($result,MYSQLI_ASSOC);
//判断用户名密码是否正确
if ($password==$data['0']['password']){
    echo '<script> alert("登录成功") </script>';
    session_start();
    $_SESSION['username']=$data['0']['username'];
    $_SESSION['role']=$data['0']['role'];
    header("refresh:0;url=../index.php");
}else{
    echo '<script> alert("登录失败") </script>';
    
    header("refresh:0;url=login.html");
}
?>